<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use App\Http\Requests\RegisterCreateRequest;

class RegisterController extends Controller
{
  protected  $fields = [
      'name' => '',
      'email' => '',
      'password' => ''
  ];
   public  function  index(){
        return view('register.index');
   }
   public function register(RegisterCreateRequest $request){
        $user = new User();
        foreach (array_keys($this->fields) as $field){
            $user->$field = $request->$field;
        }
        $user->password = bcrypt( $user->password);
        $user->save();
        return redirect("/login");
   }
}
